import uvicorn
from fastapi import FastAPI, HTTPException, status

app = FastAPI()

items = {"foo": "The foo Wreslters"}


# 添加自定义 Headers
# 在某些情况下，向 HTTP 错误添加自定义 Headers 会挺有用的

@app.get('/items-header/{item_id}')
async def read_item(item_id: str):
    if item_id not in items:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
                            detail="Item not found",
                            headers={"x-Error": "There goes my error"}
                            )

    return {"item": items[item_id]}

if __name__ == "__main__":
    uvicorn.run(app="main2:app", host="127.0.0.1", port=8000, reload=True, debug=True)
